<?php
/*
Plugin Name: stackoverflow
Plugin URI: http://www.hengha.info
Description: Crawl question from http://stackoverflow.com
Version: 1.0
Author: tomcat
Author URI: http://www.hengha.info
Text Domain: stackoverflow
Domain Path: /languages/
*/

require_once(ABSPATH . 'wp-admin/includes/taxonomy.php');
require_once(ABSPATH . 'wp-includes/taxonomy.php');
function stackoverflow_add_small_interval($schedules)
{
    if (!isset($schedules['ten-minutes'])) {
        $schedules['ten-minutes'] = array(
            'interval' => 600,
            'display' => __('Ten Minutes', 'qiushibaike')
        );
    }
    if (!isset($schedules['three-minutes'])) {
        $schedules['three-minutes'] = array(
            'interval' => 180,
            'display' => __('Three Minutes', 'qiushibaike')
        );
    }

    return $schedules;
}

add_filter('cron_schedules', 'stackoverflow_add_small_interval');

/*
function load_plugin_textdomain() {
  load_plugin_textdomain( 'qiushibaike', FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );
}

add_action( 'plugins_loaded', 'load_plugin_textdomain' );
 */

function stackoverflow_activation()
{
    wp_schedule_event(time(), 'ten-minutes', 'stackoverflow_ten_minutes_event_hook');
    wp_schedule_event(time(), 'three-minutes', 'stackoverflow_three_minutes_event_hook');
}

register_activation_hook(__FILE__, 'stackoverflow_activation');


require(__DIR__ . DIRECTORY_SEPARATOR . 'stackoverflow-question.php');
require(__DIR__ . DIRECTORY_SEPARATOR . 'stackoverflow-answer.php');
require(__DIR__ . DIRECTORY_SEPARATOR . 'stackoverflow-comment.php');


function stackoverflow_shortcode($atts)
{
    $atts = shortcode_atts(array(
        'action' => 'question'
    ), $atts, 'stackoverflow');

    switch ($atts['action']) {
        case 'question':
            stackoverflow_get_questions();
            break;
        case 'answer':
            stackoverflow_get_answers();
            break;
        default:
            break;
    }
}

add_shortcode('stackoverflow', 'stackoverflow_shortcode');

//add_action('stackoverflow_ten_minutes_event_hook', 'get_answsers');
//add_action('stackoverflow_three_minutes_event_hook', 'get_stackoverflow_comments');
function stackoverflow_deactivation()
{
    wp_clear_scheduled_hook('stackoverflow_ten_minutes_event_hook');
    wp_clear_scheduled_hook('stackoverflow_three_minutes_event_hook');
}

register_deactivation_hook(__FILE__, 'stackoverflow_deactivation');
?>
